﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace Global.Class.Library
{
    public class GlobalMsADO
    {
        public static string ServerName = "(LOCAL)";
        public static string DatabaseName = "Northwind";

        public enum UpdateOption
        {
            SaveUpdate = 1,
            SaveUndo = -1
        }

        public static string ConnectionString
        { get { return "Server = " + ServerName + "; Database= " + DatabaseName + "; Trusted_Connection= True"; } }
        //{ get { return "Server = " + ServerName + "; Database= " + DatabaseName + "; User Id=LMHIEP;Password=nomore2013"; } }

        


        private static SqlConnection mainDataAccessConnection;

        public static SqlConnection MainDataAccessConnection(bool openConnection)
        {
            try
            {
                if (mainDataAccessConnection == null || mainDataAccessConnection.State != ConnectionState.Open)
                {
                    mainDataAccessConnection = new SqlConnection(Global.Class.Library.GlobalMsADO.ConnectionString );
                    mainDataAccessConnection.Open();
                }

                return mainDataAccessConnection;
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        public static SqlConnection MainDataAccessConnection()
        {
            return mainDataAccessConnection;
        }
    }


}
